package com.wsl.springbootsecurity.repository;

import com.wsl.springbootsecurity.user.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

/**
 * @Author:WangShuliang
 * @Description:
 * @Date:Created in 14:40 2017/12/1
 * @Modified by:
 */
public class CustomUserService  implements UserDetailsService{
    @Autowired
    SysUserRepository sysUserRepository;
    @Override
    public UserDetails loadUserByUsername(String username)  {
        SysUser user = sysUserRepository.findByUsername(username);
        if (user==null){
            throw new UsernameNotFoundException("用户名不存在");
        }
        return user;
    }
}